import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  // 个人中心(以后只为自己开放)
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: '欢迎页',
    hidden: true,
    children: [
      {
        path: '/',
        component: () => import('@/views/index')
      }
    ]
  },
  {
    path: '/myself',
    component: Layout,
    redirect: '/myself/info',
    name: '个人中心',
    meta: { title: '个人中心', icon: 'table', roles: ['admin'] },
    children: [
      {
        path: 'info',
        name: '个人中心',
        component: () => import('@/views/myself/info'),
        meta: { title: '个人中心', icon: 'table' }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  // 策略管理
  {
    path: '/strategy',
    component: Layout,
    redirect: '/strategy/list',
    name: '策略管理',
    meta: {
      title: '策略管理',
      icon: 'table',
      roles: ['admin', 'root', 'editor']
    },
    children: [
      {
        path: 'list',
        name: '策略列表',
        component: () => import('@/views/strategy/list'),
        meta: {
          title: '策略列表',
          icon: 'table',
          roles: ['admin', 'root', 'editor']
        }
      },
      {
        path: 'info',
        name: '策略详情',
        hidden: true,
        component: () => import('@/views/strategy/info'),
        meta: { title: '策略详情' }
      },
      {
        path: 'save',
        name: '策略新增',
        hidden: true,
        component: () => import('@/views/strategy/save'),
        meta: { title: '策略新增' }
      },
      {
        path: 'set',
        name: '策略分配',
        hidden: true,
        component: () => import('@/views/strategy/set'),
        meta: { title: '策略分配', roles: ['admin'] }
      }
    ]
  },

  // 交易所管理
  {
    path: '/exchange',
    component: Layout,
    redirect: '/exchange/list',
    name: '交易所管理',
    meta: {
      title: '交易所管理',
      icon: 'table',
      roles: ['admin', 'root']
    },
    children: [
      {
        path: 'list',
        name: '交易所列表',
        component: () => import('@/views/exchange/list'),
        meta: { title: '交易所列表', icon: 'table' }
      },
      {
        path: 'info',
        name: '交易所详情',
        hidden: true,
        component: () => import('@/views/exchange/info'),
        meta: { title: '交易所详情' }
      }
    ]
  },

  // 用户管理(以后只为管理员开放)
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    name: '用户管理',
    meta: {
      title: '用户管理',
      icon: 'table',
      roles: ['admin']
    },
    children: [
      {
        path: 'list',
        name: '用户列表',
        component: () => import('@/views/user/list'),
        meta: {
          title: '用户列表',
          icon: 'table',
          roles: ['admin']
        }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }

]
